//CompensateJavaScript
$(function () {

    $.MvcSheet.Loaded = function () {

        var nowActivityCode = $.MvcSheetUI.SheetInfo.ActivityCode;
        var nowLoginUserId = $.MvcSheetUI.SheetInfo.UserID;
        var nowProjectNumber = $.MvcSheetUI.GetControlValue("Number03");

        var nowProcessInstanceId = $.MvcSheetUI.SheetInfo.InstanceId;

        if (nowActivityCode == "Activity2" && nowProjectNumber != "") {
            //跳过手工节点
            var SheetPostValue = $.MvcSheet.GetMvcPostValue($.MvcSheet.Action_Submit);
            var that = $.MvcSheet;
            $.MvcSheet.PostSheet({
                    Command: $.MvcSheet.Action_Submit,
                    MvcPostValue: JSON.stringify(SheetPostValue)
                },
                function (data) {
                    console.log(data);

                    swal("补偿单已发起,如果您是参与者，请在您的代办流程中查看", {
                        buttons: {
                            confim: "好的",
                        },
                        icon: "success",
                        closeOnClickOutside: false,
                    }).then((value) => {
                        $.MvcSheet.SubmitAction.OnActionDone();
                        that.ResultHandler.apply(that, [null, data]);
                    })
                }
            );
        }

        if (nowActivityCode != "Activity2" && nowActivityCode != "Activity4" && nowActivityCode != "Activity33") {

            //获取流程节点状态
            $.ajax({
                url: $.MvcSheetUI.PortalRoot + "/InstanceDetail/GetInstanceStateInfo?InstanceID=" + nowProcessInstanceId,
                type: 'GET',
                dataType: 'json',
                async: false,
                success: function (data) {
                    var instanceInfo = data.Extend.InstanceLogInfo;
                    var nowInstanceLogInfo = data.Extend.InstanceLogInfo[data.Extend.InstanceLogInfo.length - 1];
                    var nowActivityName = nowInstanceLogInfo.ActivityName;
                    $("table tr[class='rows']").hide();

                    //禁止非当前填写人
                    $("table td[data-title='" + nowInstanceLogInfo.ParticipantName + "']").parent().siblings().find("input,select").attr("disabled", true);

                    //填写一个显示一个
                    for (var i = 0; i < instanceInfo.length; i++) {
                        var personName = instanceInfo[i].ParticipantName;
                        if (null != personName && "" != personName) {
                            $("table tr[class='rows']").find("td[data-title='" + personName + "']").parent().show();
                        }

                    }

                    switch (nowActivityName) {
                        case "营业经理审核":
                            $("#viewState").text("等待营业经理审核,参与者:" + nowInstanceLogInfo.ParticipantName);
                            break;
                        case "营业副总审批":
                            $("#viewState").text("等待营业副总审核,参与者:" + nowInstanceLogInfo.ParticipantName);
                            break;
                        case "研发总监审核":
                            $("#viewState").text("等待研发总监审核,参与者:" + nowInstanceLogInfo.ParticipantName);
                            break;
                        case "质量经理审核":
                            $("#viewState").text("等待质量经理审核,参与者:" + nowInstanceLogInfo.ParticipantName);
                            break;
                        case "总经理审核":
                            $("#viewState").text("等待总经理审核,参与者:" + nowInstanceLogInfo.ParticipantName);
                            break;
                    }
                }
            })

        } else if (parseFloat($.MvcSheetUI.GetControlValue("Cost001")) < 50000) {


        }
    }

})
